package com.itcast.googleplay.holder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.googleplay.R;
import com.itcast.googleplay.bean.SubjectInfo;
import com.itcast.googleplay.http.HttpApi;
import com.itcast.googleplay.ui.RatioImageView;
import com.itcast.googleplay.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class SubjectHolder extends BaseHolder<SubjectInfo> {

	private RatioImageView imageView;
	private TextView tvDes;
	private DisplayImageOptions options;

	@Override
	public void initData() {
		options = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.ic_default)
			.showImageForEmptyUri(R.drawable.ic_default)
			.showImageOnFail(R.drawable.ic_default)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)//是否允许让图片反转
			.build();
		
		SubjectInfo info = getData();
		
		ImageLoader.getInstance().displayImage(HttpApi.IMAGEURL+info.url, imageView, options);
		tvDes.setText(info.des);
	}

	@Override
	public View initView() {
		View view = UIUtils.inflate(R.layout.list_subject_item);
		imageView = (RatioImageView) view.findViewById(R.id.riv_image);
		tvDes = (TextView) view.findViewById(R.id.tv_des);
		return view;
	}
}
